import {getCinemaList} from "../services/CinemaListServices";

export default {

  namespace: 'CinemaList',

  state: {
    list: []
  },

  subscriptions: {
    setup({ dispatch, history }) {   // eslint-disable-line
      console.log('初始化')
    },
  },

  // 异步 - redux-saga
  effects: {
    * "getCinemaList"({ payload }, { call, put }) {  // eslint-disable-line
      const res = yield call(getCinemaList);
      const {cinemas} = res.data.data;
      yield put({
        type: 'changeCinemaList',
        payload: cinemas
      });
    },
  },

  reducers: {
    changeCinemaList(prevState, action){
      return {...prevState, list: action.payload}
    }
  },

};
